﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using YouHP.Utility;
using YouHP.BLL;
using YouHP.Model;
using YouHP.Atom;
using YouHP.Logic;

namespace YouHP.Pages.TreatmentHistory
{
    public class Index : YouHP.Pages.PatientBasePage
    {
        //protected int TreatmentGraphHeight = TreatmentBaseHeight + TreatmentYGap;

        protected int diseaseId = -1;

        protected override void ShowPage()
        {
            base.ShowPage();
            if (ErrorCount > 0) return;

            HandleCommon();
            if (ErrorCount > 0) return;

            if (IsPost) HandlePost();
            else HandleGet();
        }

        protected IEnumerable<TreatmentHistoryInfo> UsingTreatmentList;
        protected IEnumerable<TreatmentHistoryInfo> StoppedTreatmentList;

        protected List<PrescriptionHistoryInfo> _listPrescList;
        protected IEnumerable<PrescriptionHistoryInfo> _listCurUsingPrescList;
        protected IEnumerable<PrescriptionHistoryInfo> _listCurNoUsingPrescList;


        protected new void HandleCommon()
        {
            this.AddLocation("治疗记录", "/TreatmentHistory/Index.aspx");
            this.SetTitle("治疗记录");
        }

        protected new void HandlePost()
        {

        }

        protected new void HandleGet()
        {
            TreatmentHistoryLogic oHistoryLogic = new TreatmentHistoryLogic();
            List<TreatmentHistoryInfo> lstCurInfos = oHistoryLogic.GetTreatmentsByPrId(PrData.Id);
  
            UsingTreatmentList = from hisinfo in lstCurInfos where hisinfo.EndDate >= DateTime.Today select hisinfo ;
            StoppedTreatmentList = from hisinfo in lstCurInfos where hisinfo.EndDate < DateTime.Today select hisinfo;
            if (UserData == null || UserData.Id <= 0)
            {
                diseaseId = 1;
            }
            else
            {
                PatientRecordInfo prInfo = PatientBLL.Instance.GetPatientRecordInfo(UserData.Id);
                if (prInfo == null || prInfo.DiseaseId <= 0)
                {
                    diseaseId = 1;
                }
                else
                {
                    diseaseId = prInfo.DiseaseId;
                }
            }
            PrescriptionHistoryLogic oPresHistoryLogic = new PrescriptionHistoryLogic();
            List<PrescriptionHistoryInfo> lstCurPresInfos = oPresHistoryLogic.GetPrescriptionsByPrId(PrData.Id);
            _listCurUsingPrescList = from hisinfo in lstCurPresInfos where hisinfo.EndDate >= DateTime.Today select hisinfo;
            _listCurNoUsingPrescList = from hisinfo in lstCurPresInfos where hisinfo.EndDate < DateTime.Today select hisinfo;
          
          
        }


    }
}